package com.cgnpc.scp.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;

public class NumberUtil {
    private static final Logger LOGGER = LoggerFactory.getLogger(NumberUtil.class);

    public static int parseIntWith0(String val) {
        return StringUtil.isNullOrSpace(val) ? 0 : Integer.parseInt(val);
    }

    public static Integer parseStringToIntegerWithNull(String val) {
        if (StringUtil.isNullOrSpace(val)) {
            return null;
        }

        if (StringUtil.isDoubleZeroSimpleString(val)) {
            return Double.valueOf(val).intValue();
        }

        return Integer.valueOf(val);
    }

    public static Long parseStringToLongWithNull(String val) {
        return StringUtil.isNullOrSpace(val) ? null : Long.valueOf(val);
    }

    public static BigDecimal parseStringToBigDecimalWithNull(String val) {
        return StringUtil.isNullOrSpace(val) ? null : new BigDecimal(val);
    }

    public static String formatLongToString(Long val) {
        return val == null ? null : val.toString();
    }

    public static String formatIntegerToString(Integer val) {
        return val == null ? null : val.toString();
    }

}
